/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package barbershop;

/**
 *
 * @author Гамзатов
 */
public class Customer extends Thread {
    private int custnr;
    public Customer(int i) {
        custnr = i+1;
    }

    @Override
    public void run() {
    
    try {
        variables.maxCapacity.acquire();
        System.out.println("Customer " + custnr + " enter shop");
        variables.mutexl.acquire();
        
        variables.mutexl.release();
        variables.sofa.acquire();
        System.out.println("Customer " + custnr + " sit on sofa");
        variables.barberChair.acquire();
        System.out.println("Customer " + custnr + " get up from sofa");
        variables.sofa.release();
        System.out.println("Customer " + custnr + " sit in barber chair");
        variables.mutex2.acquire();
        variables.enqueue.add(custnr);
        variables.cutReady.release();
        variables.mutex2.release();
        //проверка на допустимость операций
        if (custnr < variables.customerall) {
          variables.finished[custnr].acquire();
        }
        System.out.println("Customer " + custnr + " leave barber chair");
        variables.leaveBChair.release();
        System.out.println("Customer " + custnr + " pay");
        variables.payment.release();
        variables.receipt.acquire();
        variables.maxCapacity.release();
        System.out.println("Customer " + custnr + " exit shop");
        variables.alldone++;
        } catch (InterruptedException e) {
            }
    }
}
